package com.codeduck.guava.collections;

import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;

import java.util.List;

/**
 * 强大的 collection 工具集, 用于 java.util.Collections 中未提供的常见操作。
 * - 参考：https://github.com/google/guava/wiki/CollectionUtilitiesExplained
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-05-19
 */
public class Demo03 {
    public static void main(String[] args) {
        List<String> theseElements = Lists.newArrayList("alpha", "beta", "gamma");

        Iterable<Integer> concatenated = Iterables.concat(
                Ints.asList(1, 2, 3),
                Ints.asList(4, 5, 6));
        // concatenated has elements 1, 2, 3, 4, 5, 6

        Iterables.frequency(Ints.asList(1,2,3,3), 3); // return 2
        Iterable<List<Integer>> partition = Iterables.partition(Ints.asList(1, 2, 3, 3), 2);
        Iterables.getFirst(Ints.asList(1, 2, 3, 3), -1); // return 1
        Iterable<Integer> limit = Iterables.limit(Ints.asList(1, 2, 3, 3), 2);
        limit.forEach(System.out::println);
    }
}
